package com.nlscan.qdkit.ui.publico.util;


import io.reactivex.ObservableEmitter;

/**
 * Rxjava 工具类
 * Created by dyp on 2018/1/10.
 */
// TODO: 2019/6/24 delete
public class EmitterUtils {
    public static void onError(ObservableEmitter emitter, String message) {
        if (!emitter.isDisposed()) {
            emitter.onError(new Exception(message));
        }
    }

    public static void onError(ObservableEmitter emitter, int error) {
        if (!emitter.isDisposed()) {
            emitter.onError(new Exception(String.valueOf(error)));
        }
    }

    public static void onError(ObservableEmitter emitter, Throwable error) {
        if (!emitter.isDisposed()) {
            emitter.onError(error);
        }
    }

    public static void onError(ObservableEmitter emitter, ExtError error) {
        if (!emitter.isDisposed()) {
            emitter.onError(error);
        }
    }


    public static class ExtError extends Exception {
        private int result;     // 状态值
        private String cmd;
        private String extCode; // 第三方错误码
        private String extMsg;  // 第三方错误信息


        public int getResult() {
            return result;
        }

        public void setResult(int result) {
            this.result = result;
        }


        public String getCmd() {
            return cmd == null ? "" : cmd;
        }

        public void setCmd(String cmd) {
            this.cmd = cmd;
        }

        public String getExtCode() {
            return extCode == null ? "" : extCode;
        }

        public void setExtCode(String extCode) {
            this.extCode = extCode;
        }

        public String getExtMsg() {
            return extMsg == null ? "" : extMsg;
        }

        public void setExtMsg(String extMsg) {
            this.extMsg = extMsg;
        }
    }
}
